package com.library.payment.service;

import com.framework.Page;
import com.library.entity.Payment;
import com.library.payment.dao.PaymentDaoImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(readOnly=false)
public class PaymentServiceImpl {
	
	@Resource
	private PaymentDaoImpl paymentDaoImpl;

	public void addPayment(Payment payment){
		this.paymentDaoImpl.savePayment(payment);
	}

    @Transactional(readOnly=true)
	public Payment getPaymentById(Integer paymentId){
		return this.paymentDaoImpl.getPaymentById(paymentId);
	}

    @Transactional(readOnly=true)
	public Page<Payment> getPageByParams(int pageNum, int pageSize, Map paramsMap){
		return this.paymentDaoImpl.findPageByProperty(pageNum,pageSize,paramsMap);
	}
	@Transactional(readOnly=true)
	public List<Payment> getPaymentsByParams(Map paramsMap){
		return this.paymentDaoImpl.findPaymentsByProperty(paramsMap);
	}

	@Transactional(readOnly=true)
	/*查找全部缴费记录*/
	public List<Payment> getAllPayments(){
		return this.paymentDaoImpl.findPaymentsByProperty(new HashMap());
	}

	@Transactional(readOnly=true)
	/*查找全部缴费记录*/
	public Page<Payment> getAllPayments(int pageNum,int pageSize,Map paramsMap){
		return this.paymentDaoImpl.findPageByProperty(pageNum,pageSize,paramsMap);
	}

	@Transactional(readOnly=true)
	public Integer getPaymentCostByParams(Map paramsMap){
		return this.paymentDaoImpl.findCostByProperty(paramsMap).intValue();
	}

	@Transactional(readOnly=true)
	public Long getPaymentCountByParams(Map paramsMap){
		return this.paymentDaoImpl.findCountByProperty(paramsMap);
	}

	/*更新缴费记录信息*/
	public void updatePayment(Payment p){
		this.paymentDaoImpl.updatePayment(p);
	}

	/*删除指定缴费记录*/
	public void deletePayment(int paymentId){
		Payment p = this.getPaymentById(paymentId);
		this.paymentDaoImpl.deletePayment(p);
    }

	/*删除多个缴费记录*/
	public void deletePaymentGroup(int[] payments){
		Payment p = null;
		for(int i = 0;i < payments.length;++i){
			p = this.getPaymentById(payments[i]);
			this.paymentDaoImpl.deletePayment(p);
		}
	}

}
